home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / packer / mcvert / mactypes.h < prev    next >
C/C++ Source or Header  |  1994-12-17  |  7KB  |  162 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/dir.h>
  4. #include <sys/stat.h>
  5. #include <sys/timeb.h>
  6.  
  7. /* Useful, though not particularly Mac related, values */
  8. typedef unsigned char byte;     /* one byte, obviously */
  9. typedef unsigned short word;    /* must be 2 bytes */
  10. typedef unsigned long ulong;    /* 4 bytes */
  11. #define TRUE  1
  12. #define FALSE 0
  13. #define CR 0x0d
  14. #define LF 0x0a
  15.  
  16. /* Compatibility issues */
  17. #ifdef BSD
  18. #define mac2word (word) ntohs
  19. #define mac2long (ulong) ntohl
  20. #define word2mac (word) htons
  21. #define long2mac (ulong) htonl
  22. #else
  23. #define mac2word
  24. #define mac2long
  25. #define word2mac
  26. #define long2mac
  27. #endif
  28.  
  29. #ifdef MAXNAMLEN/* 4.2 BSD, stdio.h */
  30. #define SYSNAMELEN MAXNAMLEN
  31. #else
  32. #define SYSNAMELEN DIRSIZ
  33. #endif
  34.  
  35. #define NAMELEN 63              /* maximum legal Mac file name length */
  36. #define BINNAMELEN 68           /* NAMELEN + len(".bin\0") */
  37.  
  38. /* Format of a bin file:
  39. A bin file is composed of 128 byte blocks.  The first block is the
  40. info_header (see below).  Then comes the data fork, null padded to fill the
  41. last block.  Then comes the resource fork, padded to fill the last block.  A
  42. proposal to follow with the text of the Get Info box has not been implemented,
  43. to the best of my knowledge.  Version, zero1 and zero2 are what the receiving
  44. program looks at to determine if a MacBinary transfer is being initiated.
  45. */ 
  46. typedef struct {     /* info file header (128 bytes). Unfortunately, these
  47.                         longs don't align to word boundaries */
  48.             byte version;           /* there is only a version 0 at this time */
  49.             byte nlen;              /* Length of filename. */
  50.             byte name[NAMELEN];     /* Filename (only 1st nlen are significant)*/
  51.             byte type[4];           /* File type. */
  52.             byte auth[4];           /* File creator. */
  53.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  54.             byte zero1;             /* Locked, Invisible,Bundle, System */
  55.                                     /* Bozo, Busy, Changed, Init */
  56.             byte icon_vert[2];      /* Vertical icon position within window */
  57.             byte icon_horiz[2];     /* Horizontal icon postion in window */
  58.             byte window_id[2];      /* Window or folder ID. */
  59.             byte protect;           /* = 1 for protected file, 0 otherwise */
  60.             byte zero2;
  61.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  62.             byte rlen[4];           /* Resource Fork length         byte first */
  63.             byte ctim[4];           /* File's creation date. */
  64.             byte mtim[4];           /* File's "last modified" date. */
  65.             byte ilen[2];           /* GetInfo message length */
  66.         byte flags2;            /* Finder flags, bits 0-7 */
  67.         byte unused[14];       
  68.         byte packlen[4];        /* length of total files when unpacked */
  69.         byte headlen[2];        /* length of secondary header */
  70.         byte uploadvers;        /* Version of MacBinary II that the uploading program is written for */
  71.         byte readvers;          /* Minimum MacBinary II version needed to read this file */
  72.             byte crc[2];            /* CRC of the previous 124 bytes */
  73.         byte padding[2];        /* two trailing unused bytes */
  74.             } info_header;
  75.  
  76. /* The *.info file of a MacTerminal file transfer either has exactly this
  77. structure or has the protect bit in bit 6 (near the sign bit) of byte zero1.
  78. The code I have for macbin suggests the difference, but I'm not so sure */
  79.  
  80. /* Format of a hqx file:
  81. It begins with a line that begins "(This file
  82. and the rest is 64 character lines (except possibly the last, and not
  83. including newlines) where the first begins and the last ends with a colon.
  84. The characters between colons should be only from the set in tr86, below,
  85. each of which corresponds to 6 bits of data.  Once that is translated to
  86. 8 bit bytes, you have the real data, except that the byte 0x90 may 
  87. indicate, if the following character is nonzero, that the previous
  88. byte is to be repeated 1 to 255 times.  The byte 0x90 is represented by
  89. 0x9000.  The information in the file is the hqx_buf (see below),
  90. a CRC word, the data fork, a CRC word, the resource fork, and a CRC word.
  91. There is considerable confusion about the flags.  An official looking document
  92. unclearly states that the init bit is always clear, as is the following byte.
  93. The experience of others suggests, however, that this is not the case.
  94. */
  95.  
  96. #define HQXLINELEN 64
  97. typedef struct {
  98.             byte version;           /* there is only a version 0 at this time */
  99.             byte type[4];           /* File type. */
  100.             byte auth[4];           /* File creator. */
  101.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  102.             byte protect;           /* ?Pr??????, don't know what ? bits mean */
  103.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  104.             byte rlen[4];           /* Resource Fork length         byte first */
  105.             byte bugblank;             /* to fix obscure sun 3/60 problem
  106.                                           that always makes sizeof(hqx_header
  107.                                           even */
  108.             } hqx_header;
  109. typedef struct {     /* hqx file header buffer (includes file name) */
  110.             byte nlen;              /* Length of filename. */
  111.             byte name[NAMELEN];     /* Filename: only nlen actually appear */
  112.             hqx_header all_the_rest;/* and all the rest follows immediately */
  113.             } hqx_buf;
  114.  
  115. /* Format of a Packit file:
  116. Repeat the following sequence for each file in the Packit file:
  117.     4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
  118.     320 byte compression data (if compressed file)
  119.         = preorder transversal of Huffman tree
  120.         255 0 bits corresponding to nonleaf nodes
  121.         256 1 bits corresponding to leaf nodes
  122.         256 bytes associating leaf nodes with bytes
  123.         1   completely wasted bit
  124.     92 byte header (see pit_header below) *
  125.     2 bytes CRC word for header *
  126.     data fork (length from header) *
  127.     resource fork (length from header) *
  128.     2 bytes CRC word for forks *
  129.  
  130. Last file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
  131. The CRC calculations differ from those in the binhex format.
  132.  
  133. * these are in compressed form if compression is on for the file
  134.  
  135. */
  136.  
  137. typedef struct {     /* Packit file header (92 bytes) */
  138.             byte nlen;              /* Length of filename. */
  139.             byte name[NAMELEN];     /* Filename (only 1st nlen are significant)*/
  140.             byte type[4];           /* File type. */
  141.             byte auth[4];           /* File creator. */
  142.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  143.             byte zero1;
  144.             byte protect;           /* = 1 for protected file, 0 otherwise */
  145.             byte zero2;
  146.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  147.             byte rlen[4];           /* Resource Fork length         byte first */
  148.             byte ctim[4];           /* File's creation date. */
  149.             byte mtim[4];           /* File's "last modified" date. */
  150.             } pit_header;
  151.  
  152. /* types for constructing the Huffman tree */
  153. typedef struct branch_st {
  154.             byte flag;
  155.             struct branch_st *one, *zero;
  156.             } branch;
  157.  
  158. typedef struct leaf_st {
  159.             byte flag;
  160.             byte data;
  161.             } leaf;
  162.